﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Rockfan.Framework;
using Rockfan.Framework.Audio.Midi;

namespace Rockfan.Framework.Audio
{
    public sealed class TimeSignatureTrack : Track
    {
        #region Properties

        /// <summary>
        /// Gets an event within the collection at the index supplied
        /// </summary>
        /// <param name="index">a integer value indicating the index within the collection to return</param>        
        public TimeSignatureTrackEvent this[int index]
        {
            get { return Events[index]; }
        }

        /// <summary>
        /// Gets a value indicating the amount of items this object contains
        /// </summary>
        public override int Count
        {
            get { return Events.Count; }
        }

        #endregion

        #region Methods

        #region Constructor

        /// <summary>
        /// Constructs a new instance of this object
        /// </summary>
        /// <param name="name">a string value indicating the name of this object</param>
        public TimeSignatureTrack(string name)
            : base(name)
        {
            Events = new List<TimeSignatureTrackEvent>();
        }

        #endregion

        /// <summary>
        /// Sorts the entries in this collection
        /// </summary>
        internal override void SortAccending()
        {
            Events.Sort((left, right) => { return left.Start < right.Start ? -1 : left.Start > right.Start ? 1 : 0; });
        }

        /// <summary>
        /// Clears all entries within this collection
        /// </summary>
        internal override void Clear()
        {
            Events.Clear();
        }

        /// <summary>
        /// Adds an item to this collection
        /// </summary>
        /// <typeparam name="T">an object which is of type TrackEvent</typeparam>
        /// <param name="value">value must be of type 'BeatTrackEvent' or it will be ignored</param>
        internal override void AddEvent<T>(T value)
        {
            if (value.GetType() != typeof(TimeSignatureTrackEvent))
                return;

            Events.Add(value as TimeSignatureTrackEvent);
        }

        /// <summary>
        /// Removes an event from this collection
        /// </summary>
        /// <param name="value">value must be of type 'BeatTrackEvent' or it will be ignored</param>
        internal override void RemoveEvent(TrackEvent value)
        {
            if (value is TimeSignatureTrackEvent)
                Events.Remove(value as TimeSignatureTrackEvent);
        }

        /// <summary>
        /// Removes an entry at the supplied index
        /// </summary>
        /// <param name="index">an integer value indicating the location within the index to remove</param>
        internal override void RemoveEventAt(int index)
        {
            Events.RemoveAt(index);
        }

        #endregion

        private List<TimeSignatureTrackEvent> Events;
    }
}
